// page/coachs/student/record.js
var util = require("../../utils/util.js")
Page({
    data: {
        isHide: false,
        msg: {
            icon: "/images/icon/nodata.png",
            desc: "暂无记录"
        },
        startDate: util.formatDateBefore(new Date),
        endDate: util.formatDate(new Date),
        date: util.formatDate(new Date),
        topTabItems: ["已签到", "未签到"],
        currentTopItem: 0,
        list: []
    },
    onLoad: function (options) {
        var that = this
        console.log(that.data.date)
        that.request()

    },

    // 网络请求
    request: function () {
      var that = this
      wx.request({
        url: getApp().globalData.host + "&m=Coach&a=signLog", //仅为示例，并非真实的接口地址
        data: {
          uid: getApp().globalData.uid,
          ymd: that.data.date
        },
        header: {
          'content-type': 'application/json', // 默认值
        },
        method: 'POST',
        success: function (res) {
          console.log(res.data)
          //请求成功
          if (res.data.status == 1) {
            console.log(res.data)
            that.setData({
              isHide: true,
              hasSign:res.data.list1,
              noSign:res.data.list2
            })
            that.setData({
              list: that.data.hasSign
            })
          } else {//请求失败
            wx.showToast({
              title: res.data.info,
            })
          }
        },
        fail: function (res) {
          wx.showToast({
            title: "请求失败",
          })
        }
      })
    },


    //切换顶部标签
    switchTab: function (e) {
        var idx = e.currentTarget.dataset.idx
        this.setData({
            currentTopItem: idx
        })
        this.switchItems(idx)
    },
    //swiperChange
    bindChange: function (e) {
        var idx = e.detail.current
        this.setData({
            currentTopItem: idx
        })
        this.switchItems(idx)
    },
    switchItems: function (index) {
        wx.showLoading({
            title: '正在加载',
        })
        if (index == 0) {
            //已签到
            this.setData({
                list: this.data.hasSign
            })
        } else {
            //未签到
            this.setData({
                list: this.data.noSign
            })
        }
        wx.hideLoading()
    },
    bindDateChange: function (e) {
        this.setData({
            date: e.detail.value
        })
        console.log(this.data.date)
        this.request()
    },
    loadMoreData: function () {
        //加载更多
        wx.showLoading({
            title: '正在加载…',
        })
        var that = this
        var newData = []  //新数据
        if (that.data.currentTopItem == 0) {
            //已签到
            that.setData({
                list: that.data.hasSign
            })
        } else {
            //未签到
            that.setData({
                list: that.data.noSign
            })
        }
        wx.hideLoading()
    }
})